package com.fan_main;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.htmlparser.Node;
import org.htmlparser.nodes.TagNode;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;
import org.xml.sax.SAXException;
public class MyMain extends JFrame implements WindowListener {
	// 存储记录的集合
	DefaultListModel<Record> model = new DefaultListModel<Record>();
	// 显示记录的列表
	JList<Record> list = new JList<Record>(model);
	// 管理线程的哈希表
	static LinkedHashMap<String, MyThread> threadmap = new LinkedHashMap<String, MyThread>();

	public MyMain() {
		//new File("C:/Users/KK/Desktop/科技.doc")
		String basePath=System.getProperty("user.dir");
		new DynamicAddThread().addUrlFromFile(this,new File(basePath));
		JPanel p1 = new JPanel();
		list.addMouseListener(adpter);
		JScrollPane scroll = new JScrollPane(list);
		Collection<MyThread> c = threadmap.values();
		// 启东所有的线程
		Iterator it = c.iterator();
		for (; it.hasNext();) {
			((MyThread) it.next()).start();
		}
		// 把选择框加入到界面中
		int num = threadmap.size();
		int numdiv =5;// num/2+num%2;
		int rows=Math.round((1.0f*num/numdiv));
		p1.setLayout(new GridLayout(rows, numdiv));
		
		Iterator it2 = c.iterator();
		for (; it2.hasNext();) {
			p1.add(((MyThread) it2.next()).mycheck);
		}
		this.setLocation(200, 100);
		this.addWindowListener(this);
		this.setLayout(new BorderLayout());
		this.add(p1, BorderLayout.NORTH);
		this.add(scroll, BorderLayout.CENTER);
		this.setSize(600, 500);
		this.setVisible(true);
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
	}

	public synchronized void addrec(final Record rec) {

		// 界面更新放入到了Event Dispatch Thread中
		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				if(!model.contains(rec)){
					model.add(0, rec);
					//添加新闻弹窗
					TipWindow tw = new TipWindow(300, 120,rec);
					tw.setAlwaysOnTop(true);
					tw.setUndecorated(true);
					tw.setResizable(false);
					tw.setVisible(true);
					Thread thread = new Thread(tw);
					thread.start();
				}
				/*if (model.getSize() >= 51) {
					for (int i = 50; i >= 25; i--) {
						model.remove(i);
					}
				}*/
			}
		});
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		MyMain main = new MyMain();
		main.setVisible(true);
	}

	MouseAdapter adpter = new MouseAdapter() {
		public void mouseClicked(MouseEvent e) {
			if (e.getSource() == list) {
				if (e.getClickCount() == 2) {

					int index = list.locationToIndex(e.getPoint());
					try {
						URL url = new URL(model.get(index).getLink());
						// 启动默认浏览器
						Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
					} catch (MalformedURLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (IOException e2) {
						// TODO Auto-generated catch block
						e2.printStackTrace();
					}

				}

			}
		}
	};

	/*
	 * 监听发改委的线程 ps：这里采取的是xml解析方法
	 */
	MyThread mythreadnrdc = new MyThread() {

		@Override
		void method(String str) {
			// TODO Auto-generated method stub
			while (stack.size() != 0) {
				addrec(stack.pop());
			}
		}

		@Override
		public String downMethod() {
			/*
			 * 因为不同的网站，需要采取不同的分析方法，但总体而言有两种类型，1是直接用html解析器解析， 2下载关键html，本地解析
			 * 所有，以后这里需要重构
			 */
			boolean down = false;
			first = true;
			try {
				URL url = new URL(website);
				HttpURLConnection connection = (HttpURLConnection) url
						.openConnection();
				// 这里需要注意编码方式
				BufferedReader br = new BufferedReader(new InputStreamReader(
						connection.getInputStream(), "gb2312"));
				DocumentBuilderFactory domfac = DocumentBuilderFactory
						.newInstance();
				DocumentBuilder dombuilder = domfac.newDocumentBuilder();
				String line = null;
				// 采取xml解析方式，下载时添加xml头信息
				String pageHTML = "<?xml version=\"1.0\" encoding=\"gb2312\"?>\r\n<books>";
				while ((line = br.readLine()) != null) {
					if (line.indexOf("</Documents>") != -1) {
						pageHTML += "</books>";
						down = false;
						break;
					}
					if (down) {
						pageHTML += line;
					}
					if (line.indexOf("<Documents>") != -1) {
						down = true;
					}
				}
				// 网站若更新速度比较慢，则采用精确到日的时间
				Calendar cal = Calendar.getInstance();
				int year = cal.get(Calendar.YEAR);
				int month = cal.get(Calendar.MONTH) + 1;
				int day = cal.get(Calendar.DAY_OF_MONTH);
				int time = year * 372 + month * 31 + day;

				InputStream is = new ByteArrayInputStream(pageHTML.getBytes());
				org.w3c.dom.Document doc = dombuilder.parse(is);
				org.w3c.dom.Element root = doc.getDocumentElement();
				org.w3c.dom.NodeList books = root.getChildNodes();

				if (books != null) {
					for (int i = 0; i < books.getLength(); i++) {
						org.w3c.dom.NodeList nodelist = books.item(i)
								.getChildNodes();

						Record rec = new Record();
						String title = nodelist.item(1).getTextContent();
						String link = "http://www.ndrc.gov.cn/zcfb/zcfbl/"
								+ nodelist.item(3).getTextContent();
						String times = nodelist.item(5).getTextContent();
						rec.setLink(link);
						rec.setTime(times);
						rec.setTitle(title);
						if (rec.totime() == time
								&& !(rec.getTitle().equals(lasttitle))) {
							if (first) {
								temptitle = rec.getTitle();
								first = false;
							}
							stack.add(rec);

						} else {
							break;
						}

					}
					lasttitle = temptitle;
				}

			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ParserConfigurationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SAXException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}

		@Override
		void setWebname() {
			this.webname = "发改委";
		}

		@Override
		void setWebsite() {
			this.website = "http://www.ndrc.gov.cn/zcfb/zcfbl/default.htm";

		}

	};
	/*
	 * 监听东方财富的线程 ps：这里采用的是xml解析的方法
	 */
	MyThread mythreaddfcf = new MyThread() {
		@Override
		void method(String str) {
			// TODO Auto-generated method stub
			while (stack.size() != 0) {
				addrec(stack.pop());
			}
		}

		@Override
		public String downMethod() {
			boolean down = false;
			first = true;
			try {
				URL url = new URL(website);
				HttpURLConnection connection = (HttpURLConnection) url
						.openConnection();
				BufferedReader br = new BufferedReader(new InputStreamReader(
						connection.getInputStream(), "gb2312"));
				DocumentBuilderFactory domfac = DocumentBuilderFactory
						.newInstance();
				DocumentBuilder dombuilder = domfac.newDocumentBuilder();

				String line = null;
				// 添加xml文件的头信息
				String pageHTML = "<?xml version=\"1.0\" encoding=\"gb2312\"?>\r\n";
				// 截取html中感兴趣的一部分
				while ((line = br.readLine()) != null) {
					if (down && line.indexOf("</ul>") != -1) {
						pageHTML += line;
						down = false;
						break;
					}
					if (down) {
						pageHTML += line;
					}
					if (line.indexOf("artList") != -1) {
						down = true;
					}
				}
				// 解析xml解析
				InputStream is = new ByteArrayInputStream(pageHTML.getBytes());
				org.w3c.dom.Document doc = dombuilder.parse(is);
				org.w3c.dom.Element root = doc.getDocumentElement();
				org.w3c.dom.NodeList books = root.getChildNodes();

				if (books != null) {
					for (int i = 0; i < books.getLength(); i++) {

						org.w3c.dom.NodeList nodelist = books.item(i)
								.getChildNodes();
						String link = null;
						String times = null;
						String title = null;
						Record rec = new Record();
						if (nodelist.getLength() == 5) {
							// 这里出现了些莫名其妙的数字 ，最好重构下
							link = nodelist.item(4).getAttributes()
									.getNamedItem("href").getTextContent();
							times = nodelist.item(0).getTextContent();
							title = nodelist.item(4).getTextContent();
							rec.setLink(link);
							rec.setTime(times);
							rec.setTitle(title);
							if (rec.totime() > time
									&& !(rec.getTitle().equals(lasttitle))) {
								if (first) {
									temptitle = rec.getTitle();
									temptime = rec.totime();
									first = false;
								}
								stack.add(rec);

							} else {

								break;
							}

						}
					}
					time = temptime;
					lasttitle = temptitle;
				}
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ParserConfigurationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SAXException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}

		@Override
		void setWebname() {

			this.webname = "东方财富";

		}

		@Override
		void setWebsite() {
			this.website = "http://roll.eastmoney.com";

		}
	};
	/*
	 * 监听证券时报时报快讯的线程 ps：这里采取的是html解析的方法
	 */
	MyThread mythreadkx = new MyThread() {

		@Override
		void method(String str) {

			while (stack.size() != 0) {
				addrec(stack.pop());
			}
		}

		@Override
		public String downMethod() {
			try {

				String HTML = downHTML("utf-8");
				NodeList nodes = analysHTML(HTML, "span", "class",	"tit");

				int times = this.gettimtes(1);

				for (int i = 0; i < nodes.size(); i++) {
					Node node = nodes.elementAt(i).getLastChild();
					String title = node.toPlainTextString();
					String time = nodes.elementAt(i).getNextSibling().toPlainTextString().substring(1, 11);
					String strl = node.toHtml();
					TagNode tagnode = new TagNode();
					tagnode.setText(node.toHtml());
					String link =  tagnode.getAttribute("href");
					Record rec = new Record();
					rec.setLink(link);
					rec.setTime(time);
					rec.setTitle(title);
					if (rec.totime() == times
							&& !(rec.getTitle().equals(lasttitle))) {
						if (first) {
							temptitle = rec.getTitle();
							first = false;
						}
						stack.add(rec);

					} else {
						break;
					}
				}
				lasttitle = temptitle;
			} catch (ParserException e) {
				// TODO Auto-generated catch block
				System.out.println("链接不到服务器");
				// e.printStackTrace();
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block

				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}

		@Override
		void setWebname() {
			this.webname = "时报快讯";
		}

		@Override
		void setWebsite() {
			this.website = "http://kuaixun.stcn.com/index.shtml";
		}
	};
	/*
	 * 中华人民工信部
	 */
	MyThread mythreadgx = new MyThread() {

		@Override
		void method(String str) {

			while (stack.size() != 0) {
				addrec(stack.pop());
			}
		}

		@Override
		public String downMethod() {
			try {

				String HTML = downHTML("utf-8");
				NodeList nodes = analysHTML(HTML, "table", "class",
						"black14_24");

				int times = this.gettimtes(1);

				for (int i = 0; i < nodes.size(); i++) {
					Node node = nodes.elementAt(i).getFirstChild()
							.getFirstChild();
					String title = node.toPlainTextString();
					String time = node.getNextSibling().toPlainTextString();
					String strl = node.toHtml();
					TagNode tagnode = new TagNode();
					tagnode.setText(node.getFirstChild().toHtml());
					String link = "http://www.miit.gov.cn"
							+ tagnode.getAttribute("href");
					Record rec = new Record();
					rec.setLink(link);
					rec.setTime(time);
					rec.setTitle(title);
					if (rec.totime() == times
							&& !(rec.getTitle().equals(lasttitle))) {
						if (first) {
							temptitle = rec.getTitle();
							first = false;
						}
						stack.add(rec);

					} else {
						break;
					}
				}
				lasttitle = temptitle;
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ParserException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}

		@Override
		void setWebname() {
			this.webname = "工信部";

		}

		@Override
		void setWebsite() {
			this.website = "http://www.miit.gov.cn/n11293472/n11293832/n11293907/n11368277/index.html";

		}
	};

	/*
	 * 农业信息网
	 */
	MyThread mythreadly = new MyThread() {

		@Override
		void method(String str) {
			while (stack.size() != 0) {
				addrec(stack.pop());
			}

		}

		@Override
		public String downMethod() {
			try {
				int times = this.gettimtes(1);

				String HTML = downHTML("utf-8");
				NodeList nodes = analysHTML(HTML, "table", "width", "480");
				// 这个要重新设计,下面的代码
				for (int i = 0; i < nodes.size() - 1; i++) {
					Node node = nodes.elementAt(i).getFirstChild();
					String time = node.getFirstChild().getNextSibling()
							.toPlainTextString();
					time = time.substring(1, time.length() - 1);
					TagNode tagnode = new TagNode();
					String title = node.getFirstChild().getFirstChild()
							.toPlainTextString();
					tagnode.setText(node.getFirstChild().getFirstChild()
							.toHtml());
					String link = tagnode.getAttribute("href");
					link = "http://www.agri.gov.cn/V20/ZX/tzgg_1/tz"
							+ link.substring(1, link.length());
					Record rec = new Record();
					rec.setLink(link);
					rec.setTime(time);
					rec.setTitle(title);
					if (rec.totime() == times
							&& !(rec.getTitle().equals(lasttitle))) {
						if (first) {
							temptitle = rec.getTitle();
							first = false;
						}
						stack.add(rec);

					} else {
						break;
					}
				}
				lasttitle = temptitle;
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ParserException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}

		@Override
		void setWebname() {
			this.webname = "农业信息网";

		}

		@Override
		void setWebsite() {
			this.website = "http://www.agri.gov.cn/V20/ZX/tzgg_1/tz/";

		}
	};
	/*
	 * 财政部
	 */
	MyThread mythreadczb = new MyThread() {

		@Override
		void method(String str) {
			while (stack.size() != 0) {
				addrec(stack.pop());
			}

		}

		@Override
		public String downMethod() {

			try {
				int times = this.gettimtes(1);
				NodeList nodes = analysHTML("td", "class", "ZITI");
				for (int i = 0; i < nodes.size(); i++) {
					Node node = nodes.elementAt(i);
					String strl[] = node.toPlainTextString().trim().split("\n");
					String title = strl[0].trim();
					String time = strl[1].trim();
					time = time.substring(1, time.length() - 1);
					TagNode tagnode = new TagNode();
					tagnode.setText(node.getChildren().elementAt(3).toHtml());
					String link = tagnode.getAttribute("href");
					if (link.charAt(0) == '.') {
						link = "http://www.mof.gov.cn/zhengwuxinxi/zhengcefabu"
								+ link.substring(1, link.length());
					}
					Record rec = new Record();
					rec.setTime(time);
					rec.setTitle(title);
					rec.setLink(link);
					if (rec.totime() == times
							&& !(rec.getTitle().equals(lasttitle))) {
						if (first) {
							temptitle = rec.getTitle();
							first = false;
						}
						stack.add(rec);

					} else {
						break;
					}

				}
				lasttitle = temptitle;

			} catch (ParserException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}

		@Override
		void setWebname() {
			this.webname = "财政部";
		}

		@Override
		void setWebsite() {
			this.website = "http://www.mof.gov.cn/zhengwuxinxi/zhengcefabu/";
		}
	};
	/*
	 * 商务部
	 */
	MyThread mythreadswb = new MyThread() {
		LinkedList<Record> titles = new LinkedList<Record>();

		@Override
		void method(String str) {
			while (stack.size() != 0) {
				addrec(stack.pop());
			}
		}

		@Override
		public String downMethod() {
			try {
				int times = this.gettimtes(1);
				if (!titles.isEmpty()) {
					if (titles.get(0).totime() != times) {
						titles.clear();
					}
				}
				String HTML = downHTML("utf-8");
				NodeList nodes = analysHTML(HTML, "div", "class",
						"right_center_content");
				for (int i = 0; i < nodes.size(); i++) {
					NodeList nodes2 = nodes.elementAt(i).getFirstChild()
							.getChildren();
					for (int j = 0; j < nodes2.size(); j++) {
						Node node = nodes2.elementAt(j);
						if (node.getText().equals("li")) {
							Node tempnode = node.getFirstChild();
							TagNode tagnode = new TagNode();

							tagnode.setText(tempnode.toHtml());
							String link = "http://www.mofcom.gov.cn"
									+ tagnode.getAttribute("href");
							String title = tempnode.toPlainTextString();
							String time = null;

							if (i == 7) {
								time = tempnode.getNextSibling()
										.getNextSibling().toPlainTextString();
							} else {
								time = tempnode.getNextSibling()
										.toPlainTextString();

							}
							Record rec = new Record();
							rec.setLink(link);
							rec.setTime(time);
							rec.setTitle(title);

							if (rec.totime() == times) {
								int k;
								for (k = 0; k < titles.size(); k++) {
									if (titles.get(k).getTitle()
											.equals(rec.getTitle())) {
										break;
									}
								}
								if (k == titles.size()) {
									titles.add(rec);
									stack.add(rec);
								}
							}

						}
					}

				}

			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ParserException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			return null;
		}

		@Override
		void setWebname() {
			this.webname = "商务部";

		}

		@Override
		void setWebsite() {
			this.website = "http://www.mofcom.gov.cn/article/b/";

		}
	};
	/*
	 * 科技部通知
	 */
	MyThread mythreadkjbtz = new MyThread() {

		@Override
		void method(String str) {
			while (stack.size() != 0) {
				addrec(stack.pop());
			}
		}

		@Override
		public String downMethod() {

			try {

				String HTML = downHTML("gb2312");
				NodeList nodes = analysHTML(HTML, "td", "class", "STYLE30");

				int times = this.gettimtes(1);

				for (int i = 0; i < nodes.size(); i++) {
					Node node = nodes.elementAt(i).getFirstChild();
					String time = nodes.elementAt(i).getChildren().elementAt(1)
							.toPlainTextString();
					time = time.substring(1, time.length() - 1);
					String title = node.toPlainTextString();

					TagNode tagnode = new TagNode();
					tagnode.setText(node.toHtml());
					String link = tagnode.getAttribute("href");
					link = "http://www.most.gov.cn/tztg"
							+ link.substring(1, link.length());

					Record rec = new Record();
					rec.setLink(link);
					rec.setTime(time);
					rec.setTitle(title);

					if (rec.totime() == times
							&& !(rec.getTitle().equals(lasttitle))) {
						if (first) {
							temptitle = rec.getTitle();
							first = false;
						}
						stack.add(rec);

					} else {
						break;
					}
				}
				lasttitle = temptitle;
			} catch (ParserException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}

		@Override
		void setWebname() {
			this.webname = "科技部通知";

		}

		@Override
		void setWebsite() {
			this.website = "http://www.most.gov.cn/tztg/index.htm";

		}
	};

	/*
	 * 科技动向
	 */
	MyThread mythreadkjdx = new MyThread() {

		@Override
		void method(String str) {
			while (stack.size() != 0) {
				addrec(stack.pop());
			}
		}

		@Override
		public String downMethod() {

			try {
				String HTML = downHTML("gb2312");
				NodeList nodes = analysHTML(HTML, "td", "class", "STYLE30");
				int times = this.gettimtes(1);
				for (int i = 0; i < nodes.size(); i++) {
					Node node = nodes.elementAt(i).getFirstChild();
					String time = nodes.elementAt(i).getChildren().elementAt(1)
							.toPlainTextString();
					time = time.substring(1, time.length() - 1);
					String title = node.toPlainTextString();

					TagNode tagnode = new TagNode();
					tagnode.setText(node.toHtml());
					String link = tagnode.getAttribute("href");
					link = "http://www.most.gov.cn/gnwkjdt"
							+ link.substring(1, link.length());

					Record rec = new Record();
					rec.setLink(link);
					rec.setTime(time);
					rec.setTitle(title);
					// 如果时间为今天且标题不是上次看过的最新的标题，则添加
					if (rec.totime() == times
							&& !(rec.getTitle().equals(lasttitle))) {
						if (first) {
							temptitle = rec.getTitle();
							first = false;
						}
						stack.add(rec);

					} else {
						break;
					}
				}
				lasttitle = temptitle;

			} catch (ParserException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}

		@Override
		void setWebname() {
			this.webname = "科技动向";
		}

		@Override
		void setWebsite() {
			this.website = "http://www.most.gov.cn/gnwkjdt/";
		}
	};
	/*
	 * 科技动向2 这个网页的标题是分为五个部分，每个部分按时间顺序排列
	 */
	MyThread mythreadkjdx2 = new MyThread() {

		LinkedList<Record> titles = new LinkedList<Record>();

		@Override
		void method(String str) {
			while (stack.size() != 0) {
				addrec(stack.pop());
			}
		}

		@Override
		public String downMethod() {

			try {
				int times = this.gettimtes(1);
				if (!titles.isEmpty()) {
					if (titles.get(0).totime() != times) {
						titles.clear();
					}
				}

				String HTML = downHTML("gb2312");
				NodeList nodes = analysHTML(HTML, "a", "class", "STYLE30");
				if (nodes != null) {
					for (int i = 0; i < nodes.size(); i++) {

						Node node = nodes.elementAt(i);
						String tempstr = node.toPlainTextString();
						int index = tempstr.indexOf('(');

						String title = tempstr.substring(0, index);
						String time = tempstr.substring(index + 1, index + 11);

						TagNode tagnode = new TagNode();
						tagnode.setText(node.toHtml());
						String link = tagnode.getAttribute("href");
						if (link.charAt(0) == '.') {
							link = "http://www.most.gov.cn"
									+ link.substring(2, link.length());
						}

						Record rec = new Record();
						rec.setLink(link);
						rec.setTime(time);
						rec.setTitle(title);
						if (rec.totime() == times) {
							int j;
							for (j = 0; j < titles.size(); j++) {
								if (titles.get(j).getTitle()
										.equals(rec.getTitle())) {
									break;
								}
							}
							if (j == titles.size()) {
								titles.add(rec);
								stack.add(rec);
							}
						}
					}
				}
			} catch (ParserException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}

		@Override
		void setWebname() {
			this.webname = "科技动向2";
		}

		@Override
		void setWebsite() {
			this.website = "http://www.most.gov.cn/kjbgz/";

		}
	};

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowClosing(WindowEvent e) {

		System.out.println("exit");
		System.exit(EXIT_ON_CLOSE);

	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub

	}


}
